package cn.edu.nwsuaf.studentcenter.pojo;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * ExerciceExam entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "exercice_exam", catalog = "exam")
public class ExerciceExam implements java.io.Serializable {

	// Fields

	private ExerciceExamId id;
	private ExerciceItem exerciceItem;
	private Set<ExerciceExamAnswer> exerciceExamAnswers = new HashSet<ExerciceExamAnswer>(
			0);

	// Constructors

	/** default constructor */
	public ExerciceExam() {
	}

	/** minimal constructor */
	public ExerciceExam(ExerciceExamId id, ExerciceItem exerciceItem) {
		this.id = id;
		this.exerciceItem = exerciceItem;
	}

	/** full constructor */
	public ExerciceExam(ExerciceExamId id, ExerciceItem exerciceItem,
			Set<ExerciceExamAnswer> exerciceExamAnswers) {
		this.id = id;
		this.exerciceItem = exerciceItem;
		this.exerciceExamAnswers = exerciceExamAnswers;
	}

	// Property accessors
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "examNo", column = @Column(name = "exam_no", nullable = false, length = 50)),
			@AttributeOverride(name = "itemNo", column = @Column(name = "item_no", nullable = false, length = 50)) })
	public ExerciceExamId getId() {
		return this.id;
	}

	public void setId(ExerciceExamId id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "item_no", nullable = false, insertable = false, updatable = false)
	public ExerciceItem getExerciceItem() {
		return this.exerciceItem;
	}

	public void setExerciceItem(ExerciceItem exerciceItem) {
		this.exerciceItem = exerciceItem;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "exerciceExam")
	public Set<ExerciceExamAnswer> getExerciceExamAnswers() {
		return this.exerciceExamAnswers;
	}

	public void setExerciceExamAnswers(
			Set<ExerciceExamAnswer> exerciceExamAnswers) {
		this.exerciceExamAnswers = exerciceExamAnswers;
	}

}